package formats
{
	public class MoneyFormat
	{
		public function MoneyFormat()
		{
		}
		
		public function showMoney(money:String):String
		{
			return this.purseMoney(money);
		}
		
		public function getMoney(money:String):String
		{
			var str:String		=	"";
			for(var i:int=0; i<money.length; i++)
			{
				if(money.charAt(i) != "," && money.charAt(i) != " ")
				{
					str	=	str+money.charAt(i);
				}
			}
			return str;
		}
		
		public function purseMoney(money:String):String
		{
			var arr:Array	=	money.split(".");
			if(arr.length == 1)
			{
				return purseMoneyBefore(money);
			}
			else if(arr.length == 2)
			{
				var str1:String;
				str1	=	purseMoneyBefore(arr[0])+" . "+purseMoneyAfter(arr[1]);
				return str1;
			}
			return "";
		}
		
		public function purseMoneyBefore(money:String):String
		{
			var str:String	=	money.charAt(0);
			var length:int	=	money.length;
				
			for(var i:int=1; i<money.length; i++)
			{
				if(((length-i)/3).toString().length == 1)
				{
					str	=	str+" , "+money.charAt(i);
				}
				else
				{
						
					str	=	str+money.charAt(i);
				}
			}
			return str;
		}
		
		public function purseMoneyAfter(money:String):String
		{
			var str:String	=	money.charAt(0);
			var length:int	=	money.length;
				
			for(var i:int=1; i<money.length; i++)
			{
				if((i/3).toString().length == 1)
				{
					str	=	str+" , "+money.charAt(i);
				}
				else
				{
						
					str	=	str+money.charAt(i);
				}
			}
			return str;
		}
	}
}